package com.szh.cloud.mybatis.flexigrid;

import com.szh.cloud.mybatis.annotation.Columns;

import java.lang.reflect.Field;

/**
 * 分页内容
 */
public class PagingBean {
    private Integer page;
    private Integer rp;
    private String sortname;
    private String sortorder;


    public Integer getPage() {
        return page;
    }

    public Integer getPage(Integer total) {
        if(((this.page - 1)*this.rp > total)){
            this.page = 1;
            return 1;

        }
        return page;
    }

    public void setPage(Integer page) {
        this.page = page;
    }

    public Integer getRp() {
        return rp;
    }







    public void setRp(Integer rp) {
        this.rp = rp;
    }

    public String getSortname() {
        return sortname;
    }

    public void setSortname(String sortname) {
        this.sortname = sortname;
    }

    public String getSortorder() {
        return sortorder;
    }

    public void setSortorder(String sortorder) {
        this.sortorder = sortorder;
    }

    public Integer getStart() {
        return (this.page - 1) * this.rp;
    }
    @Override
    public String toString() {
        return "PagingBean{" +
                "page=" + page +
                ", rp=" + rp +
                ", sortname='" + sortname + '\'' +
                ", sortorder='" + sortorder + '\'' +
                '}';
    }

    public void deal(Class<?> classez){
        try {
            Field field = classez.getDeclaredField(this.sortname);
            if(field.isAnnotationPresent(Columns.class)){
                Columns columns = field.getDeclaredAnnotation(Columns.class);
                this.sortname = columns.value();
            }
        } catch (NoSuchFieldException e) {

        }
    }
}
